home *** CD-ROM | disk | FTP | other *** search
- //============================================================================
- // SampleModule.DLL
- // WhereIsIt Description API 2.0 Demontration Module
- // Robert Galle, July 2000
- //============================================================================
-
- {$I-}
-
- library SampleModule;
-
- uses Windows;
-
- {$DEFINE DescAPI_20}
-
- {$INCLUDE DescAPI.inc}
-
-
- //****************************************************************************
- // Implementation of "Text file import" plugin
- //****************************************************************************
-
- procedure ImportTextFile(const FileList, DescResult: PChar; RequireFileProc: TRequireFileProc);
-
- // Plugin will import the first 5 lines of text from first specified description
- // file and use it as a description for parent item (folder or archive file).
-
- // NOTE: This is a VERY simplified plugin. It does nothing special, and does
- // not include any special data checking or error recovery apart from the
- // most basic one. It should only be used as reference to Description API
- // implementation, not as a base for any "real" plugins.
-
- const NumLines = 5; // number of lines to import
-
- var StoreFileMode, n: Integer;
- TextFile: Text;
- TextFilePath: PChar;
- Line,Desc: string;
- begin
- // FileList points here to a list of found files matching plugin's file mask,
- // not in any particular order. This list is actually a single stream of
- // null-terminated strings, attached to each other, and an empty string
- // ending the list, for example:
- // 'README.TXT'#0'DESC.TXT'#0'DESC.NFO'#0'LICENSE.TXT'#0#0
- // Each plugin should decide what to do with found files, and which one to
- // use for importing. This sample plugin will just import the first file in
- // the list.
-
- // Let's request the first file in the list from WhereIsIt
- TextFilePath:=RequireFileProc(FileList);
-
- // plugin will open file as read-only, so opening should not fail even if
- // file is already opened by some other program.
- StoreFileMode:=FileMode;
- FileMode:=0; // read-only
-
- // try to open the file
- AssignFile(TextFile,TextFilePath);
- Reset(TextFile);
-
- // if something went wrong with opening the file, just leave the description
- // alone and exit
- if IOResult<>0 then Exit;
-
- try
- // read the first <NumLines> and store them in Desc
- n:=0;
- Desc:='';
- while not EOF(TextFile) and (n<NumLines) do begin
- ReadLn(TextFile,Line);
- Desc:=Desc+#13#10+Line;
- Inc(n);
- end;
- // copy the description to where it is expected (DescResult buffer),
- // but make sure not to exceed the maximum description buffer size
- // specified with MaxDescLength constant!
- LStrCpyN(DescResult,PChar(Desc),MaxDescLength-1);
- finally
- // just clean up an return
- Close(TextFile);
- FileMode:=StoreFileMode;
- end;
- end;
-
-
- //****************************************************************************
- // Description API 2.0 interface
- //****************************************************************************
-
- procedure ModuleInfoEx(ModuleInfo: TModuleInfoPtr); stdcall;
- begin
- // just provides some basic information about description module
- with ModuleInfo^ do begin
- LStrCpy(lpszModuleName, 'WhereIsIt Sample Description Module');
- LStrCpy(lpszAuthor, 'Robert Galle');
- LStrCpy(lpszVersion, '2.0');
- end;
- end;
-
- procedure ConfigureProc(HInstance: THandle; OwnerWnd: THandle; PluginID: Word); stdcall;
- begin
- // this one executes when user requests to configure plugin. In this sample
- // it will just show a simple dialog with version information.
- MessageBox(OwnerWnd,
- PChar('Sample Description Module v2.0'+#13#13'Here could be implemented a '+
- 'special dialog where users could configure the plugin.'),
- 'About SampleModule.DLL',
- MB_IconInformation+MB_OK);
- end;
-
- procedure RegisterDescPlugins(RegisterPlugin: TRegisterPlugin); stdcall;
- begin
- // register the plugin in WhereIsIt
- RegisterPlugin(0, ptParentItem, 'Text files import', '*.TXT,READ.ME', ConfigureProc);
- end;
-
- function ImportDesc_ParentItemEx(PluginID: Word; ImportParentItem: TImportParentItemPtr): Integer; stdcall;
- begin
- // This procedure is called for each ptParentItem plugin in this module. It
- // should check requested PluginID, and run the appropriate plugin. Available
- // for plugins are a list of found description files, matching plugin's
- // FileMask (FoundList parameter), and address of buffer where the extracted
- // description is expected.
-
- // assume that description will be an empty string by default
- ImportParentItem.Desc[0]:=#0;
- // call appropriate plugin by the PluginID - not much choice, we only have
- // one plugin in this sample
- IOResult;
- Result:=0;
- with ImportParentItem^ do
- case PluginID of
- 0: if FoundList>'' then ImportTextFile(FoundList,Desc,RequireFileProc)
- else Result:=-1
- else Result:=-2;
- end;
- // function should return a negative value if description was not retrieved
- // successfully, for whatever reason.
- if (ImportParentItem.Desc='') then Result:=-1;
- end;
-
-
- // The DLL library needs to export functions required by Description API 2.0
- exports
- ModuleInfoEx,
- RegisterDescPlugins,
- ImportDesc_ParentItemEx;
-
- // That's it. Simple, eh?
-
- end.
-